package com.mc.lp.database.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.mc.lp.database.dao.IStrengthAndWeaknessDAO;
import com.mc.lp.database.entity.StrengthAndWeaknessEntity;

/*
 * @author aphanda
 * @date Dec 13, 2014
 * @time 9:00:25 PM
 */


@Repository
public class StrengthAndWeaknessDAOImpl extends
		AbstractGenericHibernateDAO<StrengthAndWeaknessEntity, Long, IStrengthAndWeaknessDAO>
		implements IStrengthAndWeaknessDAO {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public List<StrengthAndWeaknessEntity> fetchDetailsByEntityIdTermGrade(Long entityId,
			int gradeId, int termId) {

		List<StrengthAndWeaknessEntity> strengthAndWeaknessList = new ArrayList<StrengthAndWeaknessEntity>();
		Criteria crit = this.getCurrentSession().createCriteria(StrengthAndWeaknessEntity.class);
		crit.add(Restrictions.eq("termId", termId));
		crit.add(Restrictions.eq("gradeId", gradeId));
		crit.add(Restrictions.eq("studentEntity", entityId));
		strengthAndWeaknessList = crit.list();
		return strengthAndWeaknessList;

	}

	@Override
	public List<StrengthAndWeaknessEntity> fetchDetailsByEntityIdYear(Long entityId, int year,
			int limit) {
		// TODO Auto-generated method stub

		List<StrengthAndWeaknessEntity> strengthAndWeaknessList = new ArrayList<StrengthAndWeaknessEntity>();
		Criteria crit = getCurrentSession().createCriteria(StrengthAndWeaknessEntity.class);
		crit.add(Restrictions.between("year", (Long.valueOf(year) - Long.valueOf(limit)),
				Long.valueOf(year + 1)));
		crit.add(Restrictions.eq("studentEntity", entityId));
		strengthAndWeaknessList = crit.list();

		return strengthAndWeaknessList;
	}

}
